const http = require('http');
const app = http.createServer();

const url = require('url');

// 创建事件
app.on('request', (req, res) => {
    let method = req.method.toLowerCase();
    let { pathname } = url.parse(req.url);

    
    res.writeHead(200, {
        'content-type': 'text/html; charset=utf8'
    });

    if (method == 'get') {
        if (pathname == '/' || pathname == '/index') {
            res.end('欢迎来到首页');
        } else if (pathname == '/list') {
            res.end('欢迎来到列表页');
        } else {
            res.end('Not found This page')
        };
    } else if (method == 'post') {
        res.end('post');
    };
});


// 监听端口
app.listen(3000);
console.log('网站服务器启动');
